#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e6 + 5;

int n, m;
int a[N];
struct Ques {
  int l, r, id;
  bool operator<(Ques x) const { return r < x.r; }
} q[N];
int ans[N];
int pre[N];
int bit[N];
int lowbit(int x) { return x & -x; }
void update(int x, int d) {
  for (int i = x; i <= n; i += lowbit(i)) bit[i] += d;
}
int query(int x) {
  int sum = 0;
  for (int i = x; i > 0; i -= lowbit(i)) sum += bit[i];
  return sum;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  cin >> m;
  rep(i, 1, m) {
    cin >> q[i].l >> q[i].r;
    q[i].id = i;
  }
  sort(q + 1, q + m + 1);
  int pos = 1;
  rep(i, 1, m) {
    while (pos <= q[i].r) {
      if (pre[a[pos]]) update(pre[a[pos]], -1);
      pre[a[pos]] = pos;
      update(pos, 1);
      pos++;
    }
    ans[q[i].id] = query(q[i].r) - query(q[i].l - 1);
  }
  rep(i, 1, m) cout << ans[i] << endl;
  return 0;
}